<script src="<?php echo $home_url; ?>/js/jquery.min.js"></script>
<script src="<?php echo $home_url; ?>/js/bootstrap.min.js"></script>
<script src="<?php echo $home_url; ?>/js/functions.js"></script>
<script>
	var home_url = "<?php echo $home_url; ?>";
	var router =  "<?php echo $router; ?>";
	var tmp,block=0;
	$(function(){
		if(router == 'login'){
			$("#form_login").center();
		}else if(router == 'products'){
			$("#request_remove_image").click(function(){
				var title,img = $("#remove_image");
				tmp = $("#remove_image").val();
				
				if(tmp == '1'){
					img.val("0");
					tmp = 0;
					title = "Không xóa logo";
					$("#img_logo").show();
					$(this).removeClass("btn-success margin15-top").addClass("btn-danger");
				}else{
					img.val("1");
					tmp = 1;
					title = "Xóa logo";
					$("#img_logo").hide();
					$(this).removeClass("btn-danger").addClass("btn-success margin15-top");
				}
				$(this).attr("data-original-title",title);
				return false;
			});
			$("#request_remove_image,#get_product_detail,#request_search").tooltip({placement: 'top'});
			
			$("#get_product_detail").click(function(){
				if(!block){
					block = 1;
					$(this).children("i").removeClass("fa-cloud-download").addClass("fa-spinner fa-spin");
					var link = $("#product_link").val();
					if(link != ''){
						$.getJSON(home_url + "/libraries/api.php",{m:'product_detail',link:link},function(data){
							console.log(data.name);
							$("#product_name").val(data.name);
							$("#product_category").val(data.category);
							$("#product_price").val(data.price);
							$("#product_photo_url").val(data.photo);
							$("#get_product_detail i.fa").removeClass("fa-spinner fa-spin").addClass("fa-cloud-download");
							$("#show-status-craw").text("Lấy dữ liệu thành công").show();
							block = 0;
							setTimeout(function(){
								$("#show-status-craw").slideUp("slow");
							},2000);
						});
					}
				}
				return false;
			});
		}
		
		$("#box-confirm .confirm").click(function(){
			var link = $("#confirm_link").val();
			location.href = link;
		});
		
		$(".show_confirm").click(function(){
			var link = this.href;
			$("#confirm_link").val(link);
			$("#box-confirm").modal("show");
			var w = $("#box-confirm .modal-dialog").outerWidth();
			var h = $("#box-confirm .modal-dialog").outerHeight();
			$("#box-confirm .modal-dialog").css({
				margin:0,padding:0,
				width:300,
				height:180,
				marginLeft:-150,
				marginTop:-90,
				top:"50%",left:"50%",
				position:"fixed"
			});
			return false;
		});
		
		$(window).load(function(){
			setTimeout(function(){
				$(".boxAlert").slideUp("slow");
			},2000);
		});
	});
</script>
</body>
</html>